package com.hxd.otc.module.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.module.my.bean.ApplyParamBean;
import com.hxd.otc.utils.StringUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/12/18 0018.
 * description ${广告申请保证金选项Adapter}
 */
public class ApplyBondAdapter extends BaseAdapter<ApplyBondAdapter.ApplyBondHolder, ApplyParamBean> {

    private int mSelPosition = -1;

    public ApplyBondAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull ApplyBondHolder holder, int position) {
        ApplyParamBean item = getItem(position);
        holder.tvOption.setText(String.format("%s %s", StringUtil.handleZero(StringUtil.handleZero(item.getCronValue())), item.getCronKey()));
        holder.tvOption.setSelected(position == mSelPosition);
    }

    @NonNull
    @Override
    public ApplyBondHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ApplyBondHolder(mInflater.inflate(R.layout.item_apply_bond, parent, false));
    }

    public void setOnSelPosition(int position) {
        int preSelPosition = mSelPosition;
        mSelPosition = position;
        if (preSelPosition != -1) {
            notifyItemChanged(preSelPosition);
        }
        notifyItemChanged(mSelPosition);
    }

    public int getSelPosition() {
        return mSelPosition;
    }

    static class ApplyBondHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_option)
        TextView tvOption;

        ApplyBondHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
